package consume.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;

import javax.jms.ConnectionFactory;
import javax.jms.Session;

/**
 * @author xiaohong
 * @version 1.0
 * @date 2021/11/14 0014 20:16
 * @description ActiveMQ配置类，配置事务和确认机制
 */
@Configuration
public class ActiveMQConfig {
    @Bean("jmsListenerContainerFactory")
    public DefaultJmsListenerContainerFactory defaultJmsListenerContainerFactory(ConnectionFactory connectionFactory){
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        factory.setConnectionFactory(connectionFactory);
        // 关闭事务
        factory.setSessionTransacted(false);
        // 修改消息确认机制 AUTO_ACKNOWLEDGE自动确认  CLIENT_ACKNOWLEDGE 手动确认 DUPS_OK_ACKNOWLEDGE延迟确认
        // 注意: SpringBoot整合ActiveMQ后， 手动消息确认值为4，而不是2 在原生的里面是2
        factory.setSessionAcknowledgeMode(4);
        return factory;
    }


}
